package com.centaline.androidsalesblog.rx.database;

import com.centaline.androidsalesblog.constants.AppConstant;
import com.centaline.androidsalesblog.model.databaseobject.BizUnitDo;

import org.litepal.crud.DataSupport;

import java.util.List;

import rx.Observable;
import rx.Subscriber;

/**
 * 获取BizUnit
 * Created by guilin on 16/2/23.
 */
final class BizUnitOnSubscribe implements Observable.OnSubscribe<BizUnitDo> {

    @Override
    public void call(Subscriber<? super BizUnitDo> subscriber) {
        final List<BizUnitDo> bizUnitDos = DataSupport.where("cityCode = ?", AppConstant.CityCode).find(BizUnitDo.class);
        if (!subscriber.isUnsubscribed() &&
                bizUnitDos != null &&
                bizUnitDos.size() > 0) {
            subscriber.onNext(bizUnitDos.get(0));
        }
        subscriber.onCompleted();
    }
}
